const app = getApp()
const request = require('../../../utils/https.js')
var fromUser, userId;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 3000,
        duration: 1000,
        height:550,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //检查服务是否暂停
        request._get(getApp().Api_url + 'system', {}, function (res) {
            if (res.data.errMsg == 'OK') {
                var flag = res.data.data.on;
                if (!flag) {
                    wx.reLaunch({
                        url: '/pages/stop1/stop1'
                    })
                    return false;
                }
            }
        }, function () {})
        console.log('options===>', options)
        const that = this;
        userId = wx.getStorageSync('userId');
        let fastId = options.urlId;

        that.setData({
            url: options.url,
            urlId: fastId
        })
        if (options.url == 'SVIP') {
            wx.setNavigationBarTitle({
                title: '直升SVIP专区'
            })
            that.fastMain(fastId, userId);
        } else if (options.url == 'VIP') {
            wx.setNavigationBarTitle({
                title: '直升VIP专区'
            })
            that.fastMain(fastId, userId);
        } else if (options.url == 'Brand') {
            wx.setNavigationBarTitle({
                title: '精选品牌'
            })
            that.mainBrand(fastId);
            that.brand(fastId, userId)
        }
    },
    //会员介绍
    lookLevel() {
        const that = this;
        let ImgLinks = 'https://oss.km3830.cn/h5/km_web.html';
        wx.navigateTo({
            url: '/pages/webview/webview?url=' + ImgLinks,
        })
    },
    //VIP-SVIP封装函数
    fastMain(fastId, userId) {
        const that = this;
        //商品列表
        request._get(getApp().Api_url + 'goods/fastMain', { //商品列表接口
            fastId: fastId,
            userId: userId,
            pageNum: 1,
            pageSize: 1000
        }, function (res) {
            if (res.data.errMsg == 'OK') {
                var dataList = res.data.data;
                that.setData({
                    dataList: dataList,
                    goodsList: dataList.children
                })

            }
        }, function () {})
    },
    mainBrand(funcId){
        const that = this;
        //精选品牌
        request._get(getApp().Api_url + 'func/main', {
            funcId: funcId
        }, function (res) {
            if (res.data.code == 200) {
                let dataList = res.data.data;
                wx.setNavigationBarTitle({
                    title: dataList.brandName
                })
                that.setData({
                    imgList: dataList.carouselsImg,
                    height:dataList.maxHeight,
                })

            }

        }, function () {})
    },

    //精选品牌
    brand(brandId, userId) {
        const that = this;
        //精选品牌
        request._get(getApp().Api_url + 'func/cateAndInfo', {
            funcId: brandId,
            userId: userId
        }, function (res) {
            if (res.data.errMsg == 'OK') {
                var dataList = res.data.data;
                that.setData({
                    dataList: dataList,
                    funcList:dataList
                })
            }

        }, function () {})
    },






    //查看详情页
    goDetails(e) {
        const that = this;

        let userId = wx.getStorageSync("userId");
        if (userId == '' || userId == null || userId == 'undefined') {
            // wx.reLaunch({
            //   url: '/pages/login/login?path=/pages/list/list'
            // })
            // return;
            userId = '';
        }
        let goodsId = e.currentTarget.dataset.goodsid;
        let goodsType = e.currentTarget.dataset.kinds;
        let fast = e.currentTarget.dataset.fast;
        wx.navigateTo({
            url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 0 + '&userId=' + fromUser + '&fast=' + fast
        })
    },
    //详情页拉起购物车
    goShopping(e) {
        const that = this;
        let userId = wx.getStorageSync("userId");
        if (userId == '' || userId == null || userId == 'undefined') {
            wx.reLaunch({
                url: '/pages/login/login?path=/pages/list/list'
            })
            return;
        }
        let goodsId = e.currentTarget.dataset.goodsid;
        let goodsType = e.currentTarget.dataset.kinds;
        let fast = e.currentTarget.dataset.fast;

        /*     let userId = wx.getStorageSync("userId");
            if (userId == '' || userId == null || userId == 'undefined') {
              wx.navigateTo({
                url: '/pages/login/login',
              })
              return;
            } */

        wx.navigateTo({
            url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 1 + '&userId=' + fromUser + '&fast=' + fast
        })
    },
    //点击图放大
    imgTapOne: function (e) {
        const that = this;
        let index = e.currentTarget.dataset.index;
        let carouselsImg = that.data.dataList.carouselsImg;
        wx.previewImage({
            current: carouselsImg[index], // 当前显示图片的http链接
            urls: carouselsImg // 需要预览的图片http链接列表
        })
    },



    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function (res) {
        const that = this;
        if (res.from === 'button') {
            // 来自页面内转发按钮

            return {
                title: '快美甄选',
                path: '/packageA/pages/voder/voder?urlId=' + that.data.urlId + '&url=' + that.data.url + '&userId=' + userId
            }
        } else {
            return {
                title: '快美甄选',
                path: '/packageA/pages/voder/voder?urlId=' + that.data.urlId + '&url=' + that.data.url + '&userId=' + userId
            }
        }
    }
})